package com.ysj.aipicturebe.controller;


import com.ysj.aipicturebe.common.BaseResponse;
import com.ysj.aipicturebe.common.ResultUtils;
import com.ysj.aipicturebe.model.dto.thumb.DoThumbRequest;
import com.ysj.aipicturebe.service.ThumbService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author pine
 */
@RestController
@RequestMapping("/thumb")
public class ThumbController {
    private static final Logger log = LoggerFactory.getLogger(ThumbController.class);


    @Resource
    private ThumbService thumbService;

    @PostMapping("/do")
    public BaseResponse<Boolean> doThumb(@RequestBody DoThumbRequest doThumbRequest, HttpServletRequest request) {
        Boolean success;
        try {
            success = thumbService.doThumb(doThumbRequest, request);
            if (success) {
                log.info("用户点赞成功");
            } else {
                log.info("用户点赞失败");
            }
        } catch (Exception e) {
            throw e;
        }
        return ResultUtils.success(success);
    }

    @PostMapping("/undo")
    public BaseResponse<Boolean> undoThumb(@RequestBody DoThumbRequest doThumbRequest, HttpServletRequest request) {
        Boolean success = thumbService.undoThumb(doThumbRequest, request);
        return ResultUtils.success(success);
    }

}
